package com.yangyu.controller;

import com.yangyu.message.BaseRsp;
import com.yangyu.message.blog.EditBlogReq;
import com.yangyu.message.blog.QueryBlogReq;
import com.yangyu.pojo.Blog;
import com.yangyu.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "博客模块")
@RestController
@RequestMapping("/blog")
public class BlogController {
    @Autowired
    private BlogService service;

    @ApiOperation("批量查询博客")
    @PostMapping("/getBlogs")
    public BaseRsp getBlogs(@RequestBody QueryBlogReq req) {
        return service.getBlogs(req);
    }

    @ApiOperation("根据id查询博客")
    @PostMapping("/getBlogById")
    public BaseRsp getBlogById(@RequestBody Blog blog) {
        return service.getBlogById(blog);
    }

    @ApiOperation("编辑博客")
    @PostMapping("/editBlog")
    public BaseRsp editBlog(@RequestBody @Valid EditBlogReq blog) {
        return service.editBlog(blog);
    }

    @ApiOperation("新增博客")
    @PostMapping("/addBlog")
    public BaseRsp addBlog(@RequestBody Blog blog) {
        return service.addBlog(blog);
    }

    @ApiOperation("删除博客")
    @PostMapping("/deleteBlog")
    public BaseRsp deleteBlog(@RequestBody Blog blog) {
        return service.deleteBlog(blog);
    }

    @ApiOperation("查询收藏的博客")
    @PostMapping("/getLikeBlogs")
    public BaseRsp getLikeBlogs(@RequestBody QueryBlogReq req) {
        return service.getLikeBlogs(req);
    }

    @ApiOperation("查询热门博客")
    @GetMapping("/getHotBlogs")
    public BaseRsp getLikeBlogs() {
        return service.getHotBlogs();
    }

    @ApiOperation("查询最新博客")
    @GetMapping("/getNewBlogs")
    public BaseRsp getNewBlogs() {
        return service.getNewBlogs();
    }
}
